// miniprogram/pages/meun/meun.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 轮播图数据
    bannerData:[
      {
        imgUrl:'cloud://rutc138237-fqk2u.7275-rutc138237-fqk2u-1301555947/banner/bga1.jpg'
      },
      {
        imgUrl:'cloud://rutc138237-fqk2u.7275-rutc138237-fqk2u-1301555947/banner/bga2.jpg'
      },
      {
        imgUrl:'cloud://rutc138237-fqk2u.7275-rutc138237-fqk2u-1301555947/banner/bga3.jpg'
      },
      {
        imgUrl:'cloud://rutc138237-fqk2u.7275-rutc138237-fqk2u-1301555947/banner/bga4.jpg'
      },
    ],
    swiperOptions:{
      autoplay:true,
      indicatorDots:true,
      indicatorColor:"#fff",
      indicatorActiveColor:"#16DAD",
      interval:"2000",
      circular:true
    },
    asideData:[
      {
        title:'最新推荐',
        isActive:true,
        key:'is_hot',
        value:1
      },
      {
        title:'大师咖啡',
        isActive:false,
        key:'type',
        value:'coffee'
      },
      {
        title:'拿铁',
        isActive:false,
        key:'type',
        value:'latte'
      },
      {
        title:'瑞纳冰',
        isActive:false,
        key:'type',
        value:'rena_ice'
      }
    ],
    productDate:[],
  },
  
  onLoad:function(){

    this.getProduct('is_hot',1)

  },
  toggleAsideMenu:function(e){

    if(e.currentTarget.dataset.active){
      return;
    }

    for(let i = 0 ; i < this.data.asideData.length ; i++){
      if(this.data.asideData[i].isActive){
        this.data.asideData[i].isActive = false;
        break;
      }
    }

    this.data.asideData[e.currentTarget.dataset.index].isActive = true

    this.setData({

      asideData:this.data.asideData

    })

    this.getProduct(e.currentTarget.dataset.key,e.currentTarget.dataset.value)


  },
  //获取商品数据
  getProduct:function(key,value){

    //加载提示

    wx.showLoading({
      title: '加载中...',
    })

    var self = this
    wx.cloud.callFunction({
      name:'get_product',
      data:{
        key:key,
        value:value
      },
      success:res=>{
      
        self.setData({
          productDate:res.result.data
        })

        wx.hideLoading()
      },
      fail:err=>{

        wx.hideLoading()
        console.log('erro=>',err)

      }

    })
  },
  //查看商品详情页面
  goDetail:function(e){
    
    var id =  e.currentTarget.dataset.id

    wx.navigateTo({
      url:'../detail/detail?id=' + id,
    })
  }

})